package com.shhm.admin.controller;

import com.shhm.admin.service.UniversityService;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.security.SecurityUser;
import com.shhm.common.entity.admin.UniversityEntity;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/17 下午5:00
 */
@RestController
@RequestMapping("/admin")
public class UniversityController {
    @Resource
    private UniversityService universityService;

    // 创建高校信息
    @PostMapping("/university")
    public AjaxResultPlus createUniversity(@RequestBody UniversityEntity dto) {
        dto.createLocalDateTime();
        SecurityUser uinfo = (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        dto.setAdminId(uinfo.getUserId());
        return universityService.createUniversity(dto);
    }

    @GetMapping("/university")
    public AjaxResultPlus pageList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer isPage,
            HttpServletRequest request
    ){
        return universityService.pageList(pageNum,pageSize,isPage,request);
    }

    // 更新高校信息
    @PutMapping("/university")
    public AjaxResultPlus updateUniversity(@RequestBody UniversityEntity dto) {
//        System.out.println(dto);
        return universityService.updateUniversity(dto);
//        return null;
    }

    // 获取高校信息（通过ID）
//    @GetMapping("/{universityId}")
//    public ResponseEntity<UniversityResponseDTO> getUniversity(@PathVariable Long universityId) {
//        UniversityResponseDTO response = universityService.getUniversityById(universityId);
//        return ResponseEntity.ok(response);
//    }

    // 删除高校信息（逻辑删除）
    @DeleteMapping("/university")
    public AjaxResultPlus deleteUniversity(@RequestBody RequestList ids) {
        return universityService.deleteUniversity(ids);
    }

    // 搜索高校信息
    @PostMapping("/university/search")
    public AjaxResultPlus searchUniversities(@RequestBody UniversityEntity dto) {
        return universityService.searchUniversities(dto);
    }
}

